﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using sipfe.model.dataAccess;
using sipfe.model.sqlExecutor;
using System.Data;

namespace sipfe.model.mante
{
    public class CacheCompendio
    {
        
        public static Hashtable hashtable = new Hashtable();

        public static List<SIPDetCompendio> getListCompendioById(decimal id)
        {
            List<SIPDetCompendio> lista = null;
            BDSIPFEEntities db = new BDSIPFEEntities();

            if (hashtable.Contains(id))
            {
                lista = (List<SIPDetCompendio>)hashtable[id];
            }
            else
            {
                //lista = db.SIPDetCompendio.Where<SIPDetCompendio>(o => o.nIdeCompendio == id && ( (DateTime.Now <= o.dtFecIniVig) && (o.dtFecFinVig.GetValueOrDefault(DateTime.Now) <= o.dtFecFinVig))).ToList();
                lista = db.SIPDetCompendio.Where<SIPDetCompendio>(o => o.nIdeCompendio == id && ((o.dFecFinVig == null && o.dFecIniVig <= DateTime.Now) || (o.dFecFinVig != null && (o.dFecIniVig <= DateTime.Now && o.dFecFinVig >= DateTime.Now)))).ToList();
                hashtable.Add(id, lista);
                //cast(getdate() as date) between dtFecIniVig and isnull(dtFecFinVig,cast(getdate() as date)) DateTime.Now
            }
            return lista;
        }
    }
}
